#pragma once
#include <stdint.h>

enum LOG_PRIORITY 
{
    LOG_PRIORITY_ALWAYS  = 0,
    LOG_PRIORITY_ERR     = 1,  // error conditions
    LOG_PRIORITY_WARNING = 2,  // warning conditions
    LOG_PRIORITY_INFO    = 3,  // informational 
    LOG_PRIORITY_DEBUG   = 4,  // debug-level messages
    LOG_PRIORITY_ERRLOG  = 5,  // 
    LOG_PRIORITY_MAX
};

#ifndef _MSC_VER // VC下在字符串前加这个宏会编译器会检查函数参数是否符合pritnf的要求
    #ifndef _Printf_format_string_
        #define _Printf_format_string_
    #endif
#endif

bool  InitLog(const char* directory, const char* identy_name, uint32_t max_line_each_file);
bool  ShutdownLog();
LOG_PRIORITY GetLogPriorityLevel();
bool  SetLogPriorityLevel(LOG_PRIORITY priority);
bool  EnableLogConsole(bool enable);
bool  WriteFormatLog(LOG_PRIORITY priority, _Printf_format_string_ const char* format, ...);
bool  WriteLog(LOG_PRIORITY priority, const char* msg);

typedef bool(*LOG_CALLBACK)(char* buffer, uint32_t length);
bool SetLogCallBack(LOG_CALLBACK callback);


#define LogAlwaysPrint(msg)     WriteLog(LOG_PRIORITY_ALWAYS,   msg)
#define LogErrPrint(msg)        WriteLog(LOG_PRIORITY_ERR,      msg)
#define LogWarningPrint(msg)    WriteLog(LOG_PRIORITY_WARNING,  msg)
#define LogInfoPrint(msg)       WriteLog(LOG_PRIORITY_INFO,     msg)
#define LogDebugPrint(msg)      WriteLog(LOG_PRIORITY_DEBUG,    msg)

#define LogAlwaysFmtPrint(format, ...)  WriteFormatLog(LOG_PRIORITY_ALWAYS,  format, ##__VA_ARGS__)
#define LogErrFmtPrint(format, ...)     WriteFormatLog(LOG_PRIORITY_ERR,     format, ##__VA_ARGS__)
#define LogWarningFmtPrint(format, ...) WriteFormatLog(LOG_PRIORITY_WARNING, format, ##__VA_ARGS__)
#define LogInfoFmtPrint(format, ...)    WriteFormatLog(LOG_PRIORITY_INFO,    format, ##__VA_ARGS__)
#define LogDebugFmtPrint(format, ...)   WriteFormatLog(LOG_PRIORITY_DEBUG,   format, ##__VA_ARGS__)
#define LogErrLogFmtPrint(format, ...)   WriteFormatLog(LOG_PRIORITY_ERRLOG, format, ##__VA_ARGS__)
